package com.x.simpleAdater;

import android.app.*;
import android.os.*;
import android.widget.*;
import java.util.*;
import android.widget.AdapterView.*;
import android.view.*;

public class MainActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		
		ArrayList<HashMap<String,Object>> listItem=new ArrayList<HashMap<String,Object>>();
		
		for(int i=0;i<10;i++)
		{
			HashMap map=new HashMap();
			map.put("ItemImage", R.drawable.ic_launcher);//加入图片
			map.put("ItemTitle", "第"+i+"行");             
			map.put("ItemText", "这是第"+i+"行");      
			listItem.add(map);
		}
		
		ListView mListView=(ListView) findViewById(R.id.mainListView1);
		
		//SimpleAdapter mSimpleAdapter=new SimpleAdapter();
		SimpleAdapter mSimpleAdapter =new SimpleAdapter(this,listItem,R.layout.entry,
		new String[] {"ItemImage","ItemTitle", "ItemText"},  
		new int[] {R.id.entryImageView1,R.id.entryTextView1,R.id.entryTextView2});

		mListView.setAdapter(mSimpleAdapter);//为ListView绑定适配器
		
		mListView.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
				{
					HashMap map=(HashMap) p1.getItemAtPosition(p3);
					Toast.makeText(MainActivity.this, (String) map.get("ItemTitle"),Toast.LENGTH_SHORT).show();;
				}
			});
    }
}
